package com.cxf.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.cxf.dao.UserDao;
import com.cxf.util.DBOperation;


public class UserDaoImpl implements UserDao {

	@Override
	public List<String> getAllMessage() {
		String sql = "SELECT * FROM messageboard";
		List<Object> param = new ArrayList<Object>();
		ResultSet res = null;
		List<String> messageList = new ArrayList<String>();	
		res = DBOperation.query(sql, param);
		try {
			while(res.next()) {
				messageList.add(res.getString("info"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return messageList;
	}

	@Override
	public void addMessage(Integer userId, String message) {
		String sql = "insert into messageboard(userName,info) values(?,?)";
		List<Object> param = new ArrayList<Object>();
		param.add(userId);
		param.add(message);
		try {
			DBOperation.update(sql, param);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
